package com.outsourcing.bottle.ui;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONObject;

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.os.Handler.Callback;
import android.os.Message;
import android.text.Html;
import android.text.TextUtils;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ext.SatelliteMenu;
import android.view.ext.SatelliteMenu.SateliteClickedListener;
import android.view.ext.SatelliteMenuItem;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.outsourcing.bottle.BasicActivity;
import com.outsourcing.bottle.R;
import com.outsourcing.bottle.db.LoginUserInfoTable;
import com.outsourcing.bottle.db.PushNoticeInfoTable;
import com.outsourcing.bottle.domain.ExFeedInfoEntry;
import com.outsourcing.bottle.domain.ExInfoSessionEntry;
import com.outsourcing.bottle.domain.ExPicOuidInfoEntry;
import com.outsourcing.bottle.domain.ExchangeInformationInfo;
import com.outsourcing.bottle.domain.LoginUserInfoEntry;
import com.outsourcing.bottle.domain.PushNoticeInfo;
import com.outsourcing.bottle.domain.UrlConfig;
import com.outsourcing.bottle.remoteimage.RemoteImageView;
import com.outsourcing.bottle.util.AppContext;
import com.outsourcing.bottle.util.BasicUIEvent;
import com.outsourcing.bottle.util.HttpUtils;
import com.outsourcing.bottle.util.ServiceUtils;
import com.outsourcing.bottle.util.TextUtil;
import com.outsourcing.bottle.util.UICore;
import com.outsourcing.bottle.widget.TryRefreshableView;

public class ExchangeInfoDetailActivity extends BasicActivity implements
		BasicUIEvent, Callback, OnClickListener {

	private final int complete_info = 1;
	
	private final int menu_uploadphoto = 105;
	private final int menu_exprofile = 104;
	private final int menu_exphoto = 103;
	private final int menu_gainbt = 102;
	private final int menu_sendbt = 101;
	private final int user_baseinfo_notfull = 100;

	private static final int EXEU_EXCHANGE_INFO_INFO = 0;
	private static final int EXEU_EXCHANGE_INFO_FAILED = 1;
	private static final int EXEU_REJECT_EX_SUCCESS = 2;
	private static final int EXEU_REJECT_EX_FAILED = 3;
	private static final int EXEU_ACCEPT_EX_SUCCESS = 4;
	private static final int EXEU_ACCEPT_EX_FAILED = 5;
	private static final int EXEU_VISIBLE_INFOEX_SUCCESS = 6;
	private static final int EXEU_VISIBLE_INFOEX_FAILED = 7;
	private static final int EXEU_INVISIBLE_INFOEX_SUCCESS = 8;
	private static final int EXEU_INVISIBLE_INFOEX_FAILED = 9;
	private static final int EXEU_REFRESH_PROFILE_INFO = 10;
	private static final int EXEU_GET_MORE_INFO_INFO = 11;
	private static final int INIT_HAS_EXS_ERROR = 12;
	private static final int EXEU_GOTO_PHOTO = 13;
	private static final int INIT_HAS_EXS_PHOTO = 14;
	private static final int EXEU_GOTO_EXCHANGE = 15;
	private static final int EXEU_DELETE_LOCATION_FEED = 16;
	private static final int EXEU_DELETE_LOCATION_SUCCESS = 17;
	private static final int EXEU_DELETE_LOCATION_FAILED = 18;
	
	Handler handler;
	private ImageView topbar_back;
	private ImageView topbar_menu;

	int page = 1, ouid;
//	private ImageLoader imageLoader = null;
	private ExchangeInformationInfo mexchangeInfo = null;
	public int exsid;

	private TryRefreshableView rv;
	private LinearLayout feed_comment;// 资料回复的item
	private LinearLayout ll_content;
	private ScrollView sv;

//	private ImageView messageView;
	private LinearLayout bottomLayout;
	private RemoteImageView avatarView;
	private TextView contentView;
	private TextView btnCount;
	private int newNoticeCount;
	private int newMessageCount;
	private int newBottleFeedCount;
	private int newExchangeFeedCount;
	private int newMaybeKownCount;
	private String message_content;
	private String message_avatar;
	private PushBroadcastReceiver receiver;
	private PushNoticeInfo pushInfo;

	@Override
	protected void onCreate(Bundle paramBundle) {
		super.onCreate(paramBundle);
		setContentView(R.layout.exchange_pic_root);
		page = getIntent().getIntExtra("page", 1);
		ouid = getIntent().getIntExtra("ouid", 0);
		handler = new Handler(this);
		initLayout();
		initSateMenu();
		UICore.eventTask(this, this, EXEU_EXCHANGE_INFO_INFO, "", null);
	}

	private void initLayout() {
		topbar_back = (ImageView) findViewById(R.id.topbar_back);
		topbar_back.setOnClickListener(this);
		topbar_menu = (ImageView) findViewById(R.id.topbar_menu);
		topbar_menu.setVisibility(View.VISIBLE);
		topbar_menu.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(ExchangeInfoDetailActivity.this,
						HomeActivity.class);
				intent.putExtra("currentItem", 0);
				startActivity(intent);
				finish();
			}
		});

//		messageView = (ImageView) findViewById(R.id.notice_message_count);
//		messageView.setOnClickListener(this);
		bottomLayout = (LinearLayout) findViewById(R.id.notice_bottom_layout);
		bottomLayout.setOnClickListener(this);
		avatarView = (RemoteImageView) findViewById(R.id.notice_avatar);
		contentView = (TextView) findViewById(R.id.notice_text);
		btnCount = (TextView) findViewById(R.id.notice_number);
//		messageView.setVisibility(View.VISIBLE);

		// refresh_view = (ElasticScrollView) findViewById(R.id.refresh_view);
		// refresh_view
		// .setonRefreshListener(new ElasticScrollView.OnRefreshListener() {
		//
		//
		//
		// @Override
		// public void onRefresh() {
		// page = 1;
		// UICore.eventTask(ExchangeInfoDetailActivity.this,
		// ExchangeInfoDetailActivity.this, EXEU_REFRESH_PROFILE_INFO, null,
		// null);
		//
		// }
		// });

		sv = (ScrollView) findViewById(R.id.trymySv);
		rv = (TryRefreshableView) findViewById(R.id.trymyRV);
		rv.mfooterView = (View) findViewById(R.id.tryrefresh_footer);
		rv.sv = sv;
		ll_content = (LinearLayout) findViewById(R.id.ll_content);
		// 隐藏mfooterView
		rv.mfooterViewText = (TextView) findViewById(R.id.tryrefresh_footer_text);
		rv.mfooterViewText.setVisibility(View.INVISIBLE);

		// 监听是否加载刷新
		rv.setRefreshListener(new TryRefreshableView.RefreshListener() {

			@Override
			public void onRefresh() {
				if (rv.mRefreshState == 4) {
					page = 1;
					UICore.eventTask(ExchangeInfoDetailActivity.this,
							ExchangeInfoDetailActivity.this,
							EXEU_REFRESH_PROFILE_INFO, null, null);
				} else if (rv.mfooterRefreshState == 4) {
					page++;
					UICore.eventTask(ExchangeInfoDetailActivity.this,
							ExchangeInfoDetailActivity.this,
							EXEU_GET_MORE_INFO_INFO, null, null);
				}

			}
		});
	}

	private void initSateMenu() {
		SatelliteMenu menu = (SatelliteMenu) findViewById(R.id.menu);
		menu.setVisibility(View.VISIBLE);
		if (CanvasWidth >= 480) {
			menu.setSatelliteDistance(200);
		} else {
			menu.setSatelliteDistance(100);
		}
		List<SatelliteMenuItem> items = new ArrayList<SatelliteMenuItem>();
		items.add(new SatelliteMenuItem(menu_exprofile,
				R.drawable.menu_exprofile));
		items.add(new SatelliteMenuItem(menu_exphoto, R.drawable.menu_exphoto));
		items.add(new SatelliteMenuItem(menu_gainbt, R.drawable.menu_gainbt));
		items.add(new SatelliteMenuItem(menu_sendbt, R.drawable.menu_sendbt));
		items.add(new SatelliteMenuItem(menu_uploadphoto, R.drawable.menu_uploadphoto));
		menu.addItems(items);
		menu.setOnItemClickedListener(new SateliteClickedListener() {

			public void eventOccured(int id) {
				switch (id) {
				case menu_sendbt: // 扔瓶子
					new Thread() {
						public void run() {
							try {
								Thread.sleep(500);
								Intent throwIntent = new Intent(
										ExchangeInfoDetailActivity.this,
										ChooseBottleActivity.class);
								throwIntent.putExtra("type", "throw");
								startActivity(throwIntent);
							} catch (InterruptedException e) {
								e.printStackTrace();
							}
						};
					}.start();
					break;
				case menu_gainbt: // 捞瓶子
					new Thread() {
						public void run() {
							try {
								Thread.sleep(500);
								Intent tryIntent = new Intent(
										ExchangeInfoDetailActivity.this,
										ChooseBottleActivity.class);
								tryIntent.putExtra("type", "try");
								startActivity(tryIntent);
							} catch (InterruptedException e) {
								e.printStackTrace();
							}
						};
					}.start();
					break;
				case menu_exphoto: // 交换照片
					new Thread() {
						public void run() {
							try {
								Thread.sleep(500);
								Intent exchangeInfoIntent = new Intent(
										ExchangeInfoDetailActivity.this,
										ChooseFriendActivity.class);
								exchangeInfoIntent
										.putExtra(
												"choose_friend_type",
												AppContext.CHOOSE_FRIEND_EXCHANGE_PHOTO_TYPE);
								startActivity(exchangeInfoIntent);
							} catch (InterruptedException e) {
								e.printStackTrace();
							}
						};
					}.start();
					break;
				case menu_exprofile: // 交换资料
					new Thread() {
						public void run() {
							try {
								Thread.sleep(500);
								LoginUserInfoTable userTable = new LoginUserInfoTable();
								LoginUserInfoEntry userEntry = userTable
										.getLoginUserInfo(AppContext
												.getInstance().getLogin_uid());
								if (userEntry.getBasicinfo_fullfill() == 0) {
									handler.sendEmptyMessage(user_baseinfo_notfull);
								} else {
									Intent exchangeFileIntent = new Intent(
											ExchangeInfoDetailActivity.this,
											ChooseFriendActivity.class);
									exchangeFileIntent
											.putExtra(
													"choose_friend_type",
													AppContext.CHOOSE_FRIEND_EXCHANGE_INFO_TYPE);
									startActivity(exchangeFileIntent);
								}
							} catch (InterruptedException e) {
								e.printStackTrace();
							}
						};
					}.start();
					break;
				case menu_uploadphoto:
					new Thread() {
						public void run() {
							try {
								Thread.sleep(500);
								Intent intent = new Intent(ExchangeInfoDetailActivity.this, ExpandEditActivity.class);
								Bundle extras = new Bundle();
								extras.putString("from_type", AppContext.UPLOAD_PHOTO);
								extras.putInt("albumid", 0);
								extras.putInt("ouid", AppContext.getInstance().getLogin_uid());
								intent.putExtras(extras);
								startActivity(intent);
							} catch (InterruptedException e) {
								e.printStackTrace();
							}
						};
					}.start();
					break;
				default:
					break;
				}
			}
		});
	}

	@Override
	public void sysMesPositiveButtonEvent(int what) {
		if (what == complete_info) {
			Intent intent = new Intent(this, SettingActivity.class);
			startActivity(intent);
		}
	}
	private void getHasExs(int ouid) {
		StringBuffer url = new StringBuffer(UrlConfig.get_has_exs);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&ouid=" + ouid);

		try {
			String result = HttpUtils.doGet(url.toString());
			if (result != null) {
				JSONObject object = new JSONObject(result);
				JSONObject resultObj = object.getJSONObject("results");
				int authok = resultObj.getInt("authok");
				if (authok == 0) {
					String errmsg = resultObj.getString("errmsg");
					Message msg = Message.obtain(handler, INIT_HAS_EXS_ERROR,
							errmsg);
					handler.sendMessage(msg);
				} else {
					JSONObject hasExsObj = object.getJSONObject("has_exs");
					int has_picexs = hasExsObj.getInt("has_picexs");
					if (has_picexs == 1) {
						handler.sendEmptyMessage(EXEU_GOTO_PHOTO);
					} else {
						handler.sendEmptyMessage(INIT_HAS_EXS_PHOTO);
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void doExchange(int ouid) {
		this.ouid = ouid;
		UICore.eventTask(this, this, EXEU_GOTO_EXCHANGE, "has_exs", null);
	}

	View view = null;

	private void setViewValue() {
		view = LayoutInflater.from(this).inflate(R.layout.exchange_pic_content, null);
		RemoteImageView iv_ovatar = (RemoteImageView) view.findViewById(R.id.iv_author_photo);
		TextView tv_onickname = (TextView) view.findViewById(R.id.tv_onickname);
		ImageView bt_sex = (ImageView) view.findViewById(R.id.bt_sex);
		TextView tv_oDoing = (TextView) view.findViewById(R.id.tv_odoing);
		TextView tv_oLocation = (TextView) view.findViewById(R.id.tv_olocation);
		Button bt_profile = (Button) view.findViewById(R.id.bt_profile);
		Button bt_album = (Button) view.findViewById(R.id.bt_ex_photo);
		Button bt_ExProfile = (Button) view.findViewById(R.id.bt_ex_profile);
		bt_ExProfile.setText(TextUtil.R("exchange_bt_ex_photo"));
		RemoteImageView iv_ovatar_2 = (RemoteImageView) view.findViewById(R.id.iv_ex_pic_ovatar_2);
		ImageView iv_ex_type = (ImageView) view.findViewById(R.id.iv_ex_type);
		TextView tv_ex_feed = (TextView) view.findViewById(R.id.tv_ex_feed);
		TextView tv_feed_time = (TextView) view.findViewById(R.id.tv_feed_time);
		RemoteImageView iv_ovatar_right = (RemoteImageView) view.findViewById(R.id.iv_ex_pic_ovatar_3);
		Button bt_ex_comment = (Button) view
				.findViewById(R.id.bt_exchange_comment);
		Button bt_ex_reject = (Button) view
				.findViewById(R.id.bt_exchange_reject);
		Button bt_ex_accept = (Button) view
				.findViewById(R.id.bt_exchange_accept);
		Button bt_ex_visible = (Button) view
				.findViewById(R.id.bt_exchange_visible);
		Button bt_ex_invisible = (Button) view
				.findViewById(R.id.bt_exchange_invisible);
		TextView tv_feed_num = (TextView) view
				.findViewById(R.id.comments_ellipsis_text);
		View line_comments_ellipsis = (View) view
				.findViewById(R.id.line_comments_ellipsis);
		View line_exchange_comment = (View) view
				.findViewById(R.id.line_exchange_comment);
		RelativeLayout feed_comments_more = (RelativeLayout) view
				.findViewById(R.id.feed_comments_more);
		feed_comment = (LinearLayout) view
				.findViewById(R.id.ll_feed_comment_layout);

		final ExPicOuidInfoEntry exPicOuidEntry = mexchangeInfo.getOuid_info();
		iv_ovatar.setDefaultImage(R.drawable.avatar_default_small);
		iv_ovatar.setImageUrl(exPicOuidEntry.getOavatar());
		iv_ovatar.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent spaceIntent = new Intent(ExchangeInfoDetailActivity.this, UserSpaceActivity.class);
				spaceIntent.putExtra("ouid", ouid);
				startActivity(spaceIntent);
			}
		});

		String onickname = null;
		if (ouid!= AppContext.getInstance()
				.getLogin_uid()) {
			onickname ="<font color='#DA4A37'>"
				+ exPicOuidEntry.getOnickname() + "</font>";
		} else {
			onickname = "<font color='#3F99D8'>"
					+ exPicOuidEntry.getOnickname() + "</font>";
		}
		// String sex = exPicOuidEntry.getOsex() == 1 ? ("("
		// + TextUtil.R("login_txt_register_male") + ")") : ("("
		// + TextUtil.R("login_txt_register_female") + ")");
		String memo = (null != exPicOuidEntry.getOmemo() && exPicOuidEntry
				.getOmemo().length() > 0) ? exPicOuidEntry.getOmemo() : "";
		tv_onickname.setText(Html.fromHtml(onickname + memo));
		int sex_res = exPicOuidEntry.getOsex() == 1 ? R.drawable.male
				: R.drawable.female;
		bt_sex.setImageResource(sex_res);
		if (null != exPicOuidEntry.getOdoing()
				&& exPicOuidEntry.getOdoing().length() > 0) {
			tv_oDoing.setVisibility(View.VISIBLE);
			String commentMood = "<font color='#000000'>"
					+ TextUtil.R("ex_comment_mood") + "</font>";
			tv_oDoing.setText(TextUtil.R("ex_comment_mood")
					+ exPicOuidEntry.getOdoing());
		} else {
			tv_oDoing.setVisibility(View.GONE);
		}
		if ((null != exPicOuidEntry.getOcountry() && exPicOuidEntry
				.getOcountry().length() > 0)
				|| (null != exPicOuidEntry.getOcity() && exPicOuidEntry
						.getOcity().length() > 0)) {
			tv_oLocation.setVisibility(View.VISIBLE);
			tv_oLocation.setText(exPicOuidEntry.getOcountry()
					+ exPicOuidEntry.getOcity());
		} else {
			tv_oLocation.setVisibility(View.GONE);
		}
		
		switch (exPicOuidEntry.getOprofile_visible()) {
		case 0://灰色
			bt_profile.setBackgroundResource(R.drawable.btn_gray_try);
			break;
		case 1://蓝色
			bt_profile.setBackgroundResource(R.drawable.btn_blue_try);
			break;
		default:
			break;
		}
		
		bt_profile.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(ExchangeInfoDetailActivity.this, UserSpaceActivity.class);
				intent.putExtra("ouid", ouid);
				startActivity(intent);
			}
		});
		bt_ExProfile.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				doExchange(ouid);
			}
		});

		if (exPicOuidEntry.getOalbum_visible() == 1) {
			bt_album.setBackgroundResource(R.drawable.btn_blue_try);
			bt_album.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					Intent intent = new Intent(ExchangeInfoDetailActivity.this,
							AlbumsActivity.class);
					intent.putExtra("ouid", ouid);
					startActivity(intent);
				}
			});
		} else {
			bt_album.setBackgroundResource(R.drawable.btn_gray_try);
			bt_album.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					ExchangeInfoDetailActivity.this.onToast(TextUtil
							.R("exchange_feed_invisible_tips"));
				}
			});
		}

		final ExInfoSessionEntry exSessionEntry = mexchangeInfo.getExs_info();
		iv_ovatar_2.setDefaultImage(R.drawable.avatar_default_small);
		iv_ovatar_2.setImageUrl(exSessionEntry.getExs_avatar());
		
		iv_ovatar_right.setDefaultImage(R.drawable.avatar_default_small);
		iv_ovatar_right.setImageUrl(exSessionEntry.getExs_oavatar());

		iv_ovatar_2.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent spaceIntent = new Intent(ExchangeInfoDetailActivity.this, UserSpaceActivity.class);
				spaceIntent.putExtra("ouid", exSessionEntry.getExs_uid());
				startActivity(spaceIntent);
			}
		});
		iv_ovatar_right.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent spaceIntent = new Intent(ExchangeInfoDetailActivity.this, UserSpaceActivity.class);
				spaceIntent.putExtra("ouid", exSessionEntry.getExs_ouid());
				startActivity(spaceIntent);
			}
		});
		iv_ex_type.setImageResource(R.drawable.btn_exprofile);

		String nickName = null;
		if (ouid!= AppContext.getInstance()
				.getLogin_uid()) {
			nickName ="<font color='#DA4A37'>"
				+ exPicOuidEntry.getOnickname() + "</font>";
		} else {
			nickName = "<font color='#3F99D8'>"
					+ exPicOuidEntry.getOnickname() + "</font>";
		}
		String mSuccess = (exSessionEntry.getExs_success() == 1) ? ("<font color='#FF3333'>"
				+ TextUtil.R("exchange_success") + "</font>")
				: ("<font color='#FF3333'>" + TextUtil.R("exchange_failed") + "</font>");
		tv_ex_feed.setText(Html.fromHtml(nickName
				+ exSessionEntry.getExs_firstfeed() + " " + mSuccess));

		if (null != tv_feed_time && tv_feed_time.length() > 0) {
			tv_feed_time.setVisibility(View.VISIBLE);
			String time = "<font color='#000000'>" + " #"
					+ exSessionEntry.getExs_firstfeedtime() + "</font>";
			tv_feed_time.setText(Html.fromHtml(time));
		} else {
			tv_feed_time.setVisibility(View.GONE);
		}
		bt_ex_comment.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent commentIntent = new Intent(
						ExchangeInfoDetailActivity.this,
						ExpandEditActivity.class);
				Bundle commentBundle = new Bundle();
				commentBundle.putString("from_type", AppContext.REPLY_INFOEX);
				commentBundle.putString("reply_infoex_type", "replay");
				commentBundle.putInt("ouid", ouid);
				commentIntent.putExtras(commentBundle);
				startActivity(commentIntent);
				finish();
			}
		});
		if (exSessionEntry.getExs_infoex_rejectshow() == 1) {
			bt_ex_reject.setVisibility(View.VISIBLE);
			bt_ex_reject.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					doRejectInfoex(ouid, exSessionEntry.getExsid());
				}
			});
		} else {
			bt_ex_reject.setVisibility(View.INVISIBLE);
		}
		if (exSessionEntry.getExs_infoex_acceptshow() == 1) {
			bt_ex_accept.setVisibility(View.VISIBLE);
			bt_ex_accept.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					doAcceptInfoex(ouid, exSessionEntry.getExsid());
				}
			});
		} else {
			bt_ex_accept.setVisibility(View.GONE);
		}
		if (exSessionEntry.getExs_infoex_visibleshow() == 1) {
			bt_ex_visible.setVisibility(View.VISIBLE);
			bt_ex_visible.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					doVisibleInfoex(ouid, exSessionEntry.getExsid());
				}
			});
		} else {
			bt_ex_visible.setVisibility(View.GONE);
		}
		if (exSessionEntry.getExs_infoex_invisibleshow() == 1) {
			bt_ex_invisible.setVisibility(View.VISIBLE);
			bt_ex_invisible.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					doInvisibleInfoex(ouid, exSessionEntry.getExsid());
				}
			});
		} else {
			bt_ex_invisible.setVisibility(View.GONE);
		}

		List<ExFeedInfoEntry> mExFeedPicEntries = mexchangeInfo
				.getExfeeds_list();
		if (null != mExFeedPicEntries && mExFeedPicEntries.size() > 0) {
			line_exchange_comment.setVisibility(View.VISIBLE);
			line_comments_ellipsis.setVisibility(View.VISIBLE);
			feed_comments_more.setVisibility(View.VISIBLE);
			tv_feed_num.setText(mexchangeInfo.getRscount() + " "
					+ TextUtil.R("bottle_txt_comment_more"));
			for (int i = 0; i < mExFeedPicEntries.size(); i++) {
				final ExFeedInfoEntry mExFeedPicEntry = mExFeedPicEntries
						.get(i);
				View feed_child = LayoutInflater.from(this).inflate(
						R.layout.exchange_comments_item, null);
				if (i == (mExFeedPicEntries.size()-1)) {
					View feed_avatar = (View) feed_child
							.findViewById(R.id.line_exchange_feed);
					feed_avatar.setVisibility(View.INVISIBLE);
				}
				RelativeLayout mfeedPhoto = (RelativeLayout) feed_child
						.findViewById(R.id.rl_exchange_feed_type);
				mfeedPhoto.setVisibility(View.GONE);
				RemoteImageView comment_profile_photo = (RemoteImageView) feed_child
						.findViewById(R.id.comment_profile_photo);
				try {
					comment_profile_photo.setDefaultImage(R.drawable.avatar_default_small);
					comment_profile_photo.setImageUrl(mExFeedPicEntry.getExfeed_avatar());
				} catch (Exception e) {
					e.printStackTrace();
					comment_profile_photo
							.setImageResource(R.drawable.avatar_default_small);
				}
				comment_profile_photo
						.setOnClickListener(new View.OnClickListener() {

							@Override
							public void onClick(View v) {
								Intent spaceIntent = new Intent(ExchangeInfoDetailActivity.this, UserSpaceActivity.class);
								spaceIntent.putExtra("ouid", mExFeedPicEntry.getExfeed_uid());
								startActivity(spaceIntent);
							}
						});
				TextView mFeedAvatar = (TextView) feed_child
						.findViewById(R.id.tv_feed_comment_nickname);
				String feed_nickname = null;
				if (mExFeedPicEntry.getExfeed_uid()!= AppContext.getInstance()
						.getLogin_uid()) {
					feed_nickname = (!TextUtils.isEmpty(mExFeedPicEntry.getExfeed_nickname())) ? ("<font color='#DA4A37'>"
							+ mExFeedPicEntry.getExfeed_nickname()+ "</font>")
							: "";
				} else {
					feed_nickname = (!TextUtils.isEmpty(mExFeedPicEntry.getExfeed_nickname())) ? ("<font color='#3F99D8'>"
							+ mExFeedPicEntry.getExfeed_nickname() + "</font>")
							: "";
				}
				
				mFeedAvatar.setText(Html.fromHtml(feed_nickname
						+ " "
						+ TextUtil.htmlEncode(mExFeedPicEntry
								.getExfeed_content())));
				TextView mFeedComment = (TextView) feed_child
						.findViewById(R.id.tv_feed_comment_content);
				if (null != mExFeedPicEntry.getExfeed_comment()
						&& mExFeedPicEntry.getExfeed_comment().length() > 0) {
					mFeedComment.setVisibility(View.VISIBLE);
					String commentTips = "<font color='#000000'>"
							+ TextUtil.R("exchange_feed_comment_title")
							+ "</font>";
					String comment = mExFeedPicEntry.getExfeed_isnew() == 1 ? ("<font color='#DA4A37'>"
							+ TextUtil.htmlEncode(mExFeedPicEntry.getExfeed_comment()) + "</font>")
							: TextUtil.htmlEncode(mExFeedPicEntry.getExfeed_comment());

					mFeedComment.setText(Html.fromHtml(commentTips + comment));
				} else {
					mFeedComment.setVisibility(View.GONE);
				}
				TextView mFeedTime = (TextView) feed_child
						.findViewById(R.id.tv_feed_comment_time);

				String time = (!TextUtils.isEmpty(mExFeedPicEntry
						.getExfeed_time())) ? (" #" + mExFeedPicEntry
						.getExfeed_time()) : "";
				String location = (!TextUtils.isEmpty(mExFeedPicEntry
						.getExfeed_location())) ? (" @" + mExFeedPicEntry
						.getExfeed_location()) : "";
				mFeedTime.setText(time + location);
				if (location.length() > 0) {
					mFeedTime.setOnClickListener(new View.OnClickListener() {

						@Override
						public void onClick(View v) {

							if (mExFeedPicEntry.getLocation_delete_enable() == 1) {
								final Context dialogContext = new ContextThemeWrapper(
										ExchangeInfoDetailActivity.this,
										android.R.style.Theme_Light);
								String[] choices = new String[2];
								choices[0] = getString(R.string.bottle_txt_check_location);
								choices[1] = getString(R.string.bottle_txt_clean_location);

								final ListAdapter adapter = new ArrayAdapter<String>(
										dialogContext,
										android.R.layout.simple_list_item_1,
										choices);

								final AlertDialog.Builder builder = new AlertDialog.Builder(
										dialogContext);
								builder.setTitle(R.string.system_info);
								builder.setSingleChoiceItems(adapter, -1,
										new DialogInterface.OnClickListener() {

											public void onClick(
													DialogInterface dialog,
													int which) {
												dialog.dismiss();
												if (which == 0) {
													dialog.dismiss();
													Intent intent = new Intent(
															ExchangeInfoDetailActivity.this,
															MapViewActivity.class);
													intent.putExtra("longitude",
															mExFeedPicEntry
																	.getExfeed_lng());
													intent.putExtra("latidute",
															mExFeedPicEntry
																	.getExfeed_lat());
													intent.putExtra(
															"location",
															mExFeedPicEntry
																	.getExfeed_location());
													startActivity(intent);
												} else {
													UICore.eventTask(
															ExchangeInfoDetailActivity.this,
															ExchangeInfoDetailActivity.this,
															EXEU_DELETE_LOCATION_FEED,"",mExFeedPicEntry);
												}
											}
										});
								builder.create().show();
							} else {
								
							final Context dialogContext = new ContextThemeWrapper(
									ExchangeInfoDetailActivity.this,
									android.R.style.Theme_Light);
							String[] choices = new String[1];
							choices[0] = getString(R.string.bottle_txt_check_location);

							final ListAdapter adapter = new ArrayAdapter<String>(
									dialogContext,
									android.R.layout.simple_list_item_1,
									choices);

							final AlertDialog.Builder builder = new AlertDialog.Builder(
									dialogContext);
							builder.setTitle(R.string.system_info);
							builder.setSingleChoiceItems(adapter, -1,
									new DialogInterface.OnClickListener() {
										public void onClick(
												DialogInterface dialog,
												int which) {
											dialog.dismiss();
											Intent intent = new Intent(
													ExchangeInfoDetailActivity.this,
													MapViewActivity.class);
											intent.putExtra("longitude",
													mExFeedPicEntry
															.getExfeed_lng());
											intent.putExtra("latidute",
													mExFeedPicEntry
															.getExfeed_lat());
											intent.putExtra(
													"location",
													mExFeedPicEntry
															.getExfeed_location());
											startActivity(intent);
										}
									});
							builder.create().show();
						  }

						}
					});
				}
				feed_comment.addView(feed_child);
			}
		} else {
			line_exchange_comment.setVisibility(View.GONE);
			line_comments_ellipsis.setVisibility(View.GONE);
			feed_comments_more.setVisibility(View.GONE);
		}
		// refresh_view.addChild(view);
		ll_content.addView(view);
		rv.mfooterViewText.setVisibility(View.VISIBLE);
		ServiceUtils.dout("CanvasHeight:" + CanvasHeight);
		ServiceUtils.dout("ll_content.getHeight():" + ll_content.getHeight());
		ServiceUtils.dout("ll_content.getLayoutParams().height:"
				+ ll_content.getLayoutParams().height);
	}

	public void doInvisibleInfoex(int ouid, int exsid) {
		this.ouid = ouid;
		this.exsid = exsid;
		UICore.eventTask(this, this, EXEU_INVISIBLE_INFOEX_SUCCESS, "", null);
	}

	private void invisibleInfoex(int ouid) {
		StringBuffer url = new StringBuffer(UrlConfig.invisible_infoex);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&ouid=" + ouid);

		ServiceUtils.dout("invisibleInfoex url: " + url.toString());

		try {
			String results = HttpUtils.doGet(url.toString());
			ServiceUtils.dout("invisibleInfoex result:" + results);
			if (null != results) {
				JSONObject obj = new JSONObject(results);
				JSONObject resultObj = obj.getJSONObject("results");
				int success = resultObj.getInt("success");
				String errmsg = resultObj.getString("errmsg");
				String successmsg = resultObj.getString("successmsg");
				if (success == 1) {
					Message message = handler.obtainMessage(
							EXEU_INVISIBLE_INFOEX_SUCCESS, successmsg);
					handler.sendMessage(message);

				} else {
					Message message = handler.obtainMessage(
							EXEU_INVISIBLE_INFOEX_FAILED, errmsg);
					handler.sendMessage(message);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void doVisibleInfoex(int ouid, int exsid) {
		this.ouid = ouid;
		this.exsid = exsid;
		UICore.eventTask(this, this, EXEU_VISIBLE_INFOEX_SUCCESS, "", null);
	}

	private void visibleInfoex(int ouid) {
		StringBuffer url = new StringBuffer(UrlConfig.visible_infoex);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&ouid=" + ouid);

		ServiceUtils.dout("visibleInfoex url: " + url.toString());

		try {
			String results = HttpUtils.doGet(url.toString());
			ServiceUtils.dout("visibleInfoex result:" + results);
			if (null != results) {
				JSONObject obj = new JSONObject(results);
				JSONObject resultObj = obj.getJSONObject("results");
				int success = resultObj.getInt("success");
				String errmsg = resultObj.getString("errmsg");
				String successmsg = resultObj.getString("successmsg");
				if (success == 1) {
					Message message = handler.obtainMessage(
							EXEU_VISIBLE_INFOEX_SUCCESS, successmsg);
					handler.sendMessage(message);

				} else {
					Message message = handler.obtainMessage(
							EXEU_VISIBLE_INFOEX_FAILED, errmsg);
					handler.sendMessage(message);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void doAcceptInfoex(int ouid, int exsid) {
		this.ouid = ouid;
		this.exsid = exsid;

		LoginUserInfoTable loginUserInfoTable = new LoginUserInfoTable();
		LoginUserInfoEntry loginUserInfoEntry = loginUserInfoTable
				.getLoginUserInfo(AppContext.getInstance().getLogin_uid());
		if (null != loginUserInfoEntry
				&& loginUserInfoEntry.getBasicinfo_fullfill() == 0) {
			String basicinfo_tip = loginUserInfoEntry.getBasicinfo_tip();
			AlertDialog.Builder alertDialog = new AlertDialog.Builder(
					ExchangeInfoDetailActivity.this);
			alertDialog.setMessage(basicinfo_tip);
			alertDialog.setPositiveButton(TextUtil.R("confirm_ok"),
					new DialogInterface.OnClickListener() {

						@Override
						public void onClick(DialogInterface dialog, int which) {
							Intent intent = new Intent(
									ExchangeInfoDetailActivity.this,
									SettingActivity.class);
							startActivity(intent);
						}
					});
			alertDialog.setNegativeButton(TextUtil.R("confirm_cancel"),
					new DialogInterface.OnClickListener() {

						@Override
						public void onClick(DialogInterface dialog, int which) {

						}
					});
			alertDialog.create().show();

		} else {
			UICore.eventTask(this, this, EXEU_ACCEPT_EX_SUCCESS, "", null);
		}
	}

	private void acceptInfoex(int ouid) {
		StringBuffer url = new StringBuffer(UrlConfig.accept_infoex);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&ouid=" + ouid);

		ServiceUtils.dout("acceptInfoex url: " + url.toString());

		try {
			String results = HttpUtils.doGet(url.toString());
			ServiceUtils.dout("acceptInfoex result:" + results);
			if (null != results) {
				JSONObject obj = new JSONObject(results);
				JSONObject resultObj = obj.getJSONObject("results");
				int success = resultObj.getInt("success");
				String errmsg = resultObj.getString("errmsg");
				String successmsg = resultObj.getString("successmsg");
				if (success == 1) {
					Message message = handler.obtainMessage(
							EXEU_ACCEPT_EX_SUCCESS, successmsg);
					handler.sendMessage(message);

				} else {
					Message message = handler.obtainMessage(
							EXEU_ACCEPT_EX_FAILED, errmsg);
					handler.sendMessage(message);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void doRejectInfoex(int ouid, int exsid) {
		this.ouid = ouid;
		this.exsid = exsid;
		UICore.eventTask(this, this, EXEU_REJECT_EX_SUCCESS, "", null);
	}

	private void rejectInfoex(int ouid) {
		StringBuffer url = new StringBuffer(UrlConfig.reject_infoex);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&ouid=" + ouid);

		ServiceUtils.dout("rejectInfoex url: " + url.toString());

		try {
			String results = HttpUtils.doGet(url.toString());
			ServiceUtils.dout("rejectInfoex result:" + results);
			if (null != results) {
				JSONObject obj = new JSONObject(results);
				JSONObject resultObj = obj.getJSONObject("results");
				int success = resultObj.getInt("success");
				String errmsg = resultObj.getString("errmsg");
				String successmsg = resultObj.getString("successmsg");
				if (success == 1) {
					Message message = handler.obtainMessage(
							EXEU_REJECT_EX_SUCCESS, successmsg);
					handler.sendMessage(message);

				} else {
					Message message = handler.obtainMessage(
							EXEU_REJECT_EX_FAILED, errmsg);
					handler.sendMessage(message);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}


	@Override
	public void execute(int mes, Object obj) {
		switch (mes) {
		case EXEU_EXCHANGE_INFO_INFO:
			getExchangeInfo(ouid, page);
			break;
		case EXEU_REJECT_EX_SUCCESS:
			rejectInfoex(ouid);
			break;
		case EXEU_ACCEPT_EX_SUCCESS:
			acceptInfoex(ouid);
			break;
		case EXEU_VISIBLE_INFOEX_SUCCESS:
			visibleInfoex(ouid);
			break;
		case EXEU_INVISIBLE_INFOEX_SUCCESS:
			invisibleInfoex(ouid);
			break;
		case EXEU_REFRESH_PROFILE_INFO:
			refreshExchangeInfo(ouid, page);
			break;
		case EXEU_GET_MORE_INFO_INFO:
			getMoreExchangeInfo(ouid, page);
			break;
		case EXEU_GOTO_EXCHANGE:
			getHasExs(ouid);
			break;
		case EXEU_DELETE_LOCATION_FEED:
			ExFeedInfoEntry mExFeedPicEntry = (ExFeedInfoEntry)obj;
			deleteLocation(String.valueOf(mExFeedPicEntry.getLocation_objtype()),String.valueOf(mExFeedPicEntry.getLocation_objid()));
			break;
		default:
			break;
		}
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		try {
			if (receiver != null) {
				unregisterReceiver(receiver);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void getExchangeInfo(int ouid, int page) {
		StringBuffer url = new StringBuffer(UrlConfig.get_infoex);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&ouid=" + ouid);
		url.append("&count=10");
		url.append("&page=" + page);
		ServiceUtils.dout("getExchangeInfo url: " + url.toString());
		try {
			String results = HttpUtils.doGet(url.toString());

			if (results == null) {
				return;
			}
			ServiceUtils.dout("getExchangeInfo results:" + results);
			Gson gson = new Gson();
			mexchangeInfo = gson.fromJson(results,
					ExchangeInformationInfo.class);
			if (mexchangeInfo.getResults().getAuthok() == 1) {
				PushNoticeInfoTable table = new PushNoticeInfoTable();
				pushInfo = table.getPushNoticeInfo(AppContext.getInstance()
						.getLogin_uid());
				if (null != pushInfo) {
					newBottleFeedCount = pushInfo.getNew_btfeed_count();
					newExchangeFeedCount = pushInfo.getNew_exfeed_count();
					newMessageCount = pushInfo.getNew_message_count();
					newNoticeCount = pushInfo.getNew_notice_count();
					message_content = pushInfo.getMessage_content();
					message_avatar = pushInfo.getMessage_avatar();
					newMaybeKownCount = pushInfo.getNew_maybeknow_count();
				}
				Message message = handler
						.obtainMessage(EXEU_EXCHANGE_INFO_INFO);
				handler.sendMessage(message);
			} else {
				Message message = handler.obtainMessage(
						EXEU_EXCHANGE_INFO_FAILED, mexchangeInfo.getResults()
								.getErrmsg());
				handler.sendMessage(message);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void getMoreExchangeInfo(int ouid, int page) {
		StringBuffer url = new StringBuffer(UrlConfig.get_infoex);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&ouid=" + ouid);
		url.append("&count=10");
		url.append("&page=" + page);
		ServiceUtils.dout("getExchangeInfo url: " + url.toString());
		try {
			String results = HttpUtils.doGet(url.toString());

			if (results == null) {
				return;
			}
			ServiceUtils.dout("getExchangeInfo results:" + results);
			Gson gson = new Gson();
			mexchangeInfo = gson.fromJson(results,
					ExchangeInformationInfo.class);
			if (mexchangeInfo.getResults().getAuthok() == 1) {
				Message message = handler
						.obtainMessage(EXEU_GET_MORE_INFO_INFO);
				handler.sendMessage(message);
			} else {
				Message message = handler.obtainMessage(
						EXEU_EXCHANGE_INFO_FAILED, mexchangeInfo.getResults()
								.getErrmsg());
				handler.sendMessage(message);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void refreshExchangeInfo(int ouid, int page) {
		StringBuffer url = new StringBuffer(UrlConfig.get_infoex);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&ouid=" + ouid);
		url.append("&count=20");
		url.append("&page=" + page);
		ServiceUtils.dout("getExchangeInfo url: " + url.toString());
		try {
			String results = HttpUtils.doGet(url.toString());

			if (results == null) {
				return;
			}
			ServiceUtils.dout("getExchangeInfo results:" + results);
			Gson gson = new Gson();
			mexchangeInfo = gson.fromJson(results,
					ExchangeInformationInfo.class);
			if (mexchangeInfo.getResults().getAuthok() == 1) {
				Message message = handler
						.obtainMessage(EXEU_REFRESH_PROFILE_INFO);
				handler.sendMessage(message);
			} else {
				Message message = handler.obtainMessage(
						EXEU_EXCHANGE_INFO_FAILED, mexchangeInfo.getResults()
								.getErrmsg());
				handler.sendMessage(message);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public boolean handleMessage(Message msg) {
		switch (msg.what) {
		case EXEU_EXCHANGE_INFO_INFO:
			ll_content.removeAllViews();
			setViewValue();
			pushNoticeUpdateUI();
			receiver = new PushBroadcastReceiver();
			IntentFilter filter = new IntentFilter();
			filter.addAction("push");
			registerReceiver(receiver, filter);
			break;
		case EXEU_REFRESH_PROFILE_INFO:
			// refresh_view.removeChild(view);
			ll_content.removeAllViews();
			setViewValue();
			rv.finishRefresh();
			// refresh_view.onRefreshComplete();
			break;
		case EXEU_EXCHANGE_INFO_FAILED:
			onToast((String) msg.obj);
			break;
		case EXEU_REJECT_EX_SUCCESS:
			page = 1;
			UICore.eventTask(this, this, EXEU_EXCHANGE_INFO_INFO, "", null);
			break;
		case EXEU_REJECT_EX_FAILED:
			onToast((String) msg.obj);
			break;
		case EXEU_ACCEPT_EX_SUCCESS:
			page = 1;
			UICore.eventTask(this, this, EXEU_EXCHANGE_INFO_INFO, "", null);
			break;
		case EXEU_ACCEPT_EX_FAILED:
			onToast((String) msg.obj);
			break;
		case EXEU_VISIBLE_INFOEX_SUCCESS:
			page = 1;
			UICore.eventTask(this, this, EXEU_EXCHANGE_INFO_INFO, "", null);
			break;
		case EXEU_VISIBLE_INFOEX_FAILED:
			onToast((String) msg.obj);
			break;
		case EXEU_INVISIBLE_INFOEX_SUCCESS:
			page = 1;
			UICore.eventTask(this, this, EXEU_EXCHANGE_INFO_INFO, "", null);
			break;
		case EXEU_INVISIBLE_INFOEX_FAILED:
			onToast((String) msg.obj);
			break;
		case EXEU_GET_MORE_INFO_INFO:
			List<ExFeedInfoEntry> mExFeedInfoEntries = mexchangeInfo
					.getExfeeds_list();
			if (null != mExFeedInfoEntries && mExFeedInfoEntries.size() > 0) {
				setMoreFeed(mExFeedInfoEntries);
			} else {
				onToast(TextUtil.R("no_more_data"));
			}
			rv.finishRefresh();
			break;
		case INIT_HAS_EXS_ERROR:
			onToast((String) msg.obj);
			break;
		case EXEU_GOTO_PHOTO:
			Intent intentExchangePic = new Intent(this,
					ExchangePicDetailActivity.class);
			intentExchangePic.putExtra("ouid", ouid);
			intentExchangePic.putExtra("page", 1);
			startActivity(intentExchangePic);
			break;
		case INIT_HAS_EXS_PHOTO:
			Intent intentPhoto = new Intent(this, ExpandEditActivity.class);
			Bundle bundlePhoto = new Bundle();
			bundlePhoto.putString("from_type", AppContext.APPLY_PICEX);
			bundlePhoto.putInt("ouid", ouid);
			intentPhoto.putExtras(bundlePhoto);
			startActivity(intentPhoto);
			finish();
			break;
		case user_baseinfo_notfull:
			LoginUserInfoTable userTable = new LoginUserInfoTable();
			LoginUserInfoEntry userEntry = userTable.getLoginUserInfo(AppContext.getInstance().getLogin_uid());
			showChoseMes(userEntry.getBasicinfo_tip(), complete_info);
			break;
		case EXEU_DELETE_LOCATION_SUCCESS:
			page = 1;
			UICore.eventTask(this, this, EXEU_EXCHANGE_INFO_INFO, "", null);
			break;
		case EXEU_DELETE_LOCATION_FAILED:
			onToast((String) msg.obj);
			break;
		default:
			break;
		}
		return false;
	}

	private void setMoreFeed(List<ExFeedInfoEntry> mExFeedInfoEntries) {

		for (int i = 0; i < mExFeedInfoEntries.size(); i++) {
			final ExFeedInfoEntry mExFeedPicEntry = mExFeedInfoEntries.get(i);
			View feed_child = LayoutInflater.from(this).inflate(
					R.layout.exchange_comments_item, null);
			RelativeLayout mfeedPhoto = (RelativeLayout) feed_child
					.findViewById(R.id.rl_exchange_feed_type);
			mfeedPhoto.setVisibility(View.GONE);
			RemoteImageView comment_profile_photo = (RemoteImageView) feed_child
					.findViewById(R.id.comment_profile_photo);
			try {
				comment_profile_photo.setDefaultImage(R.drawable.avatar_default_small);
				comment_profile_photo.setImageUrl(mExFeedPicEntry.getExfeed_avatar());
			} catch (Exception e) {
				e.printStackTrace();
				comment_profile_photo
						.setImageResource(R.drawable.avatar_default_small);
			}
			comment_profile_photo
					.setOnClickListener(new View.OnClickListener() {

						@Override
						public void onClick(View v) {
							Intent spaceIntent = new Intent(ExchangeInfoDetailActivity.this, UserSpaceActivity.class);
							spaceIntent.putExtra("ouid", mExFeedPicEntry.getExfeed_uid());
							startActivity(spaceIntent);
						}
					});
			TextView mFeedAvatar = (TextView) feed_child
					.findViewById(R.id.tv_feed_comment_nickname);
			String feed_nickname = null;
			if (mExFeedPicEntry.getExfeed_uid()!= AppContext.getInstance()
					.getLogin_uid()) {
				feed_nickname = (!TextUtils.isEmpty(mExFeedPicEntry.getExfeed_nickname())) ? ("<font color='#DA4A37'>"
						+ mExFeedPicEntry.getExfeed_nickname()+ "</font>")
						: "";
			} else {
				feed_nickname = (!TextUtils.isEmpty(mExFeedPicEntry.getExfeed_nickname())) ? ("<font color='#3F99D8'>"
						+ mExFeedPicEntry.getExfeed_nickname() + "</font>")
						: "";
			}
			
			mFeedAvatar.setText(Html.fromHtml(feed_nickname
					+ " "
					+ TextUtil.htmlEncode(mExFeedPicEntry
							.getExfeed_content())));
			TextView mFeedComment = (TextView) feed_child
					.findViewById(R.id.tv_feed_comment_content);
			if (null != mExFeedPicEntry.getExfeed_comment()
					&& mExFeedPicEntry.getExfeed_comment().length() > 0) {
				mFeedComment.setVisibility(View.VISIBLE);
				String commentTips = "<font color='#000000'>"
						+ TextUtil.R("exchange_feed_comment_title") + ":"
						+ "</font>";
				String comment = mExFeedPicEntry.getExfeed_isnew() == 1 ? ("<font color='#DA4A37'>"
						+ TextUtil.htmlEncode(mExFeedPicEntry.getExfeed_comment()) + "</font>")
						: TextUtil.htmlEncode(mExFeedPicEntry.getExfeed_comment());

						
						
				mFeedComment.setText(Html.fromHtml(commentTips
						+ comment));
			} else {
				mFeedComment.setVisibility(View.GONE);
			}
			TextView mFeedTime = (TextView) feed_child
					.findViewById(R.id.tv_feed_comment_time);

			String time = (mExFeedPicEntry.getExfeed_time() != null && mExFeedPicEntry
					.getExfeed_time().length() > 0) ? (" #" + mExFeedPicEntry
					.getExfeed_time()) : "";
			String location = (null != mExFeedPicEntry.getExfeed_location() && mExFeedPicEntry
					.getExfeed_location().length() > 0) ? (" @" + mExFeedPicEntry
					.getExfeed_location()) : "";
			mFeedTime.setText(time + location);

			if (location.length() > 0) {
				mFeedTime.setOnClickListener(new View.OnClickListener() {

					@Override
					public void onClick(View v) {

						final Context dialogContext = new ContextThemeWrapper(
								ExchangeInfoDetailActivity.this,
								android.R.style.Theme_Light);
						String[] choices = new String[1];
						choices[0] = getString(R.string.bottle_txt_check_location);

						final ListAdapter adapter = new ArrayAdapter<String>(
								dialogContext,
								android.R.layout.simple_list_item_1, choices);

						final AlertDialog.Builder builder = new AlertDialog.Builder(
								dialogContext);
						builder.setTitle(R.string.system_info);
						builder.setSingleChoiceItems(adapter, -1,
								new DialogInterface.OnClickListener() {
									public void onClick(DialogInterface dialog,
											int which) {
										dialog.dismiss();
										Intent intent = new Intent(
												ExchangeInfoDetailActivity.this,
												MapViewActivity.class);
										intent.putExtra("longitude",
												mExFeedPicEntry.getExfeed_lng());
										intent.putExtra("latidute",
												mExFeedPicEntry.getExfeed_lat());
										intent.putExtra("location",
												mExFeedPicEntry
														.getExfeed_location());
										startActivity(intent);
									}
								});
						builder.create().show();
					}
				});
			}
			feed_comment.addView(feed_child);
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.topbar_back:
			finish();
			break;
//		case R.id.notice_message_count:
//			doMessageAction();
//			break;
		case R.id.notice_bottom_layout:
			doFeedsAction();
			break;
		default:
			break;
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);

		if (null != data) {
			if (data.getBooleanExtra("need_refresh", false)) {
				page = 1;
				UICore.eventTask(this, this, EXEU_EXCHANGE_INFO_INFO, "", null);
			}
		}
	}

	public void doMessageAction() {

		final Context dialogContext = new ContextThemeWrapper(this,
				android.R.style.Theme_Light);
		String[] choices = new String[2];
		if (newNoticeCount > 0) {
			choices[0] = newNoticeCount
					+ getString(R.string.bottle_txt_notice_list);
		} else {
			choices[0] = getString(R.string.bottle_txt_notice_list);
		}
		if (newMessageCount > 0) {
			choices[1] = newMessageCount
					+ getString(R.string.bottle_txt_message_list);
		} else {
			choices[1] = getString(R.string.bottle_txt_message_list);
		}

		final ListAdapter adapter = new ArrayAdapter<String>(dialogContext,
				android.R.layout.simple_list_item_1, choices);

		final AlertDialog.Builder builder = new AlertDialog.Builder(
				dialogContext);
		builder.setTitle(R.string.system_info);
		builder.setSingleChoiceItems(adapter, -1,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
						if (which == 0) {
							Intent intent = new Intent(
									ExchangeInfoDetailActivity.this,
									NoticeListActivity.class);
							startActivity(intent);
						} else {
							Intent intent = new Intent(
									ExchangeInfoDetailActivity.this,
									MessageListActivity.class);
							startActivity(intent);
						}
					}
				});
		builder.create().show();
	}


	/**
	 * 
	 * @param objtype 要清除的位置的类型：选择项：（1）瓶子动态的位置信息、（2）交换动态留言的位置信息、（3）照片评论的位置信息、（4）私信的位置信息、（5）照片的位置信息
	 * @param objid objid
	 */
	private void deleteLocation(String objtype,String objid) {
		StringBuffer url = new StringBuffer(UrlConfig.delete_location);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&objtype=" + objtype);
		url.append("&objid=" + objid);
		ServiceUtils.dout("deleteLocation url:" + url.toString());
		try {
			String result = HttpUtils.doGet(url.toString());
			ServiceUtils.dout("deleteLocation result:" + result);
			JSONObject obj = new JSONObject(result);
			JSONObject resultObj = obj.getJSONObject("results");
			int success = resultObj.getInt("success");
			String errmsg = resultObj.getString("errmsg");
			String successmsg = resultObj.getString("successmsg");
			if (success == 1) {
				Message message = handler.obtainMessage(
						EXEU_DELETE_LOCATION_SUCCESS, successmsg);
				handler.sendMessage(message);
			} else {
				Message message = handler.obtainMessage(
						EXEU_DELETE_LOCATION_FAILED, errmsg);
				handler.sendMessage(message);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void doFeedsAction() {
		final Context dialogContext = new ContextThemeWrapper(this, android.R.style.Theme_Light);
		final List<String> choices = new ArrayList<String>(); 
		if (newBottleFeedCount > 0) {
			choices.add(newBottleFeedCount + getString(R.string.bottle_txt_new_bottle_feed));
		}
		if (newExchangeFeedCount > 0) {
			choices.add(newExchangeFeedCount + getString(R.string.bottle_txt_new_exchange_feed));
		}
		if (newNoticeCount > 0) {
			choices.add(newNoticeCount + getString(R.string.bottle_txt_notice_list));
		}
		if (newMessageCount > 0) {
			choices.add(newMessageCount + getString(R.string.bottle_txt_message_list));
		}
		if (newMaybeKownCount > 0) {
			choices.add(newMaybeKownCount + getString(R.string.bottle_txt_new_maybe_kown));
		}
		final ListAdapter adapter = new ArrayAdapter<String>(dialogContext, android.R.layout.simple_list_item_1, choices);
		final AlertDialog.Builder builder = new AlertDialog.Builder(dialogContext);
		builder.setTitle(R.string.system_info);
		builder.setSingleChoiceItems(adapter, -1,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
						if (choices.get(which).indexOf(getString(R.string.bottle_txt_new_bottle_feed)) != -1) {
							Intent intent = new Intent(ExchangeInfoDetailActivity.this, HomeActivity.class);
							AppContext.getInstance().setCurrentItem(1);
							startActivity(intent);
						} else if (choices.get(which).indexOf(getString(R.string.bottle_txt_new_exchange_feed)) != -1) {
							Intent intent = new Intent(ExchangeInfoDetailActivity.this, HomeActivity.class);
							AppContext.getInstance().setCurrentItem(0);
							startActivity(intent);
						} else if (choices.get(which).indexOf(getString(R.string.bottle_txt_notice_list)) != -1) {
							Intent intent = new Intent(ExchangeInfoDetailActivity.this, NoticeListActivity.class);
							startActivity(intent);
						} else if (choices.get(which).indexOf(getString(R.string.bottle_txt_message_list)) != -1) {
							Intent intent = new Intent(ExchangeInfoDetailActivity.this, MessageListActivity.class);
							startActivity(intent);
						} else if (choices.get(which).indexOf(getString(R.string.bottle_txt_new_maybe_kown)) != -1) {
							Intent intent = new Intent(ExchangeInfoDetailActivity.this, HomeActivity.class);
							AppContext.getInstance().setCurrentItem(2);
							AppContext.getInstance().setGotoMaybeKown(true);
							startActivity(intent);
						}
					}
				});
		builder.create().show();
	}
	
	public void pushNoticeUpdateUI() {
		if (newBottleFeedCount + newExchangeFeedCount + newMessageCount + newNoticeCount + newMaybeKownCount > 0) {
			bottomLayout.setVisibility(View.VISIBLE);
			contentView.setText(message_content);
			btnCount.setText(newBottleFeedCount + newExchangeFeedCount + newMessageCount + newNoticeCount + newMaybeKownCount  + "");
			avatarView.setDefaultImage(R.drawable.avatar_default_big);
			avatarView.setImageUrl(message_avatar);
		} else {
			bottomLayout.setVisibility(View.GONE);
		}
	}
	
	public class PushBroadcastReceiver extends BroadcastReceiver {

		@Override
		public void onReceive(Context context, Intent intent) {
			Bundle bundle = intent.getExtras();
			if (bundle != null) {
				newBottleFeedCount = bundle.getInt("bottle_feed_count");
				newExchangeFeedCount = bundle.getInt("exchange_feed_count");
				newMessageCount = bundle.getInt("message_count");
				newNoticeCount = bundle.getInt("notice_count");
				message_content = bundle.getString("message_content");
				message_avatar = bundle.getString("message_avatar");
				newMaybeKownCount = bundle.getInt("maybe_kown_count");
				pushNoticeUpdateUI();
			}
		}
	}
}
